package com.redpacketcover.rc.base;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProviders;

public class ViewModelFactory {

    public static <T extends ViewModel> T getInstance(Class<T> modelClass, BasicView iView) {
        if (iView instanceof BasicActivity) {
            return ViewModelProviders.of((BasicActivity) iView).get(modelClass);
        } else if (iView instanceof BasicFragment) {
            return ViewModelProviders.of((BasicFragment) iView).get(modelClass);
        } else if (iView instanceof BasicLazyFragment) {
            return ViewModelProviders.of((BasicLazyFragment) iView).get(modelClass);
        } else {
            throw new IllegalArgumentException("iView类型错误");
        }
    }
}
